package cn.iocoder.yudao.module.book.dal.mysql.checkIn;

import java.time.LocalDateTime;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.book.dal.dataobject.checkIn.CheckInDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.book.controller.admin.checkIn.vo.*;
import org.apache.ibatis.annotations.Param;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * 打卡 Mapper
 *
 * @author xi
 */
@Mapper
public interface CheckInMapper extends BaseMapperX<CheckInDO> {

    default PageResult<CheckInDO> selectPage(CheckInPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CheckInDO>()
                .eqIfPresent(CheckInDO::getUserId, reqVO.getUserId())
                .eqIfPresent(CheckInDO::getBookList, reqVO.getBookList())
                .eqIfPresent(CheckInDO::getContent, reqVO.getContent())
                .eqIfPresent(CheckInDO::getDayCount, reqVO.getDayCount())
                .eqIfPresent(CheckInDO::getCheckInType, reqVO.getCheckInType())
                .eqIfPresent(CheckInDO::getClassId, reqVO.getClassId())
                .betweenIfPresent(CheckInDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CheckInDO::getClockId));
    }

    Integer selectDayCount(@Param("userId") Long userId);

    CheckInDO selectBook(@Param("userId") Long userId,@Param("time") String time);

    boolean selectNowDay(@Param("userId")@NotNull(message = "用户id不能为空") Long userId,@Param("time") @NotEmpty(message = "时间不能为空") LocalDateTime createTime);

    /**
     * 根据打卡类型检查今日是否已经打卡
     */
    boolean selectNowDayByType(@Param("userId") Long userId, @Param("time") LocalDateTime createTime, @Param("checkInType") Integer checkInType);

    /**
     * 根据用户ID列表查询打卡记录
     */
    List<CheckInDO> selectByUserIds(@Param("userIds") List<Long> userIds);
}
